package com.blog.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blog.service.PostService;
import com.blog.service.Impl.PostServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Servlet implementation class deletePost1Servlet
 */
@WebServlet("/deletePost.do")
public class deletePost1Servlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int postId =request.getParameter("postId") == null ? 1: Integer.parseInt(request.getParameter("postId"));
		int userId =request.getParameter("userId") == null ? 1: Integer.parseInt(request.getParameter("userId"));
		PostService ps = new PostServiceImpl();
		response.setContentType("application/json;charset=utf-8");
		new ObjectMapper().writeValue(response.getWriter(), ps.deletePost(postId,userId));
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
